﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using AjaxPro.Services;

namespace Rison.Web.NRBZ
{
    public partial class NRFBDetail : XWFBPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(departid))
                {
                    this.LoadInformation();
                }                
            }

            //AjaxPro.Utility.RegisterTypeForAjax(typeof(NRFBDetail));
        }

        //[AjaxPro.AjaxMethod]
        public override void LoadInformation()
        {
           
            LabTBRQ.Text = "填报日期：" + System.DateTime.Today.ToShortDateString();
            DataRow dr = RetriveNrbz();
            if (dr != null)
            {
                HiddenID.Value = dr["ID"].ToString();
                Hiddentotal.Value=dr["FieldTotal"].ToString();
                Hiddencurtotoal.Value = dr["FieldNum"].ToString();
                if (!String.IsNullOrEmpty(dr["LastModifiedTime"].ToString()))
                {
                    this.LabTBRQ.Text = "最后更新日期：" + dr["LastModifiedTime"].ToString();
                }
                if (!String.IsNullOrEmpty(dr["State"].ToString()))
                {
                    this.Hiddenstate.Value = dr["State"].ToString();
                }
                else
                {
                    this.Hiddenstate.Value = "0";
                }
            }

            this.XWFBDetail1.LoadInformation(dr);
            this.ZfgkDetail1.LoadInformation(dr);
            this.ZfbsDetail1.LoadInformation(dr);
            this.HdqdDetail1.LoadInformation(dr);
            this.GgfwDetail1.LoadInformation(dr);
            this.ZwzglDetail1.LoadInformation(dr);

        }

        //[AjaxPro.AjaxMethod]
        public void btnSave_Click(object sender, EventArgs e)
        {
            if ("1".Equals(this.Hiddenstate.Value))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('信息已经提交，不能再次修改');</script>");
                return;
            }
            try
            {
                long returnValue = 0;
                string rv = this.XWFBDetail1.SaveInformation("0", Convert.ToInt16(this.Hiddentotal.Value), Convert.ToInt16(this.Hiddencurtotoal.Value));
                returnValue = this.ZfgkDetail1.SaveInformation();
                returnValue = this.ZfbsDetail1.SaveInformation();
                returnValue = this.HdqdDetail1.SaveInformation();
                returnValue = this.GgfwDetail1.SaveInformation();
                returnValue = this.ZwzglDetail1.SaveInformation();
               

                if (returnValue >= 0)
                {
                    if (Request.Params["ajax"] == "true")
                    {
                        //this.LoadInformation();
                        Response.Redirect(String.Format("NRFBAjaxSave.ashx?id={0}", rv));
                        return;
                    }
                    string errormessage = HistorySave(this.HiddenID.Value);
                    Response.Redirect("NRFBDetail.aspx?DepartID=" + departid + "&type=2");
                }
                else
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('保存错误');</script>");
            }
            catch(Exception e1)
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", String.Format("<script>alert('{0}');</script>",e1.Message));
            }
        }

        public void btnSubmit_Click(object sender, EventArgs e)
        {
            if ("1".Equals(this.Hiddenstate.Value))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('信息已经提交，不能再次修改');</script>");
                return;
            }
            try
            {
                long returnValue = 0;
                string rv = this.XWFBDetail1.SaveInformation("1", Convert.ToInt16(this.Hiddentotal.Value), Convert.ToInt16(this.Hiddencurtotoal.Value));
                returnValue = this.ZfgkDetail1.SaveInformation();
                returnValue = this.ZfbsDetail1.SaveInformation();
                returnValue = this.HdqdDetail1.SaveInformation();
                returnValue = this.GgfwDetail1.SaveInformation();
                returnValue = this.ZwzglDetail1.SaveInformation();


                if (returnValue >= 0)
                {
                    string errormessage = HistorySave(this.HiddenID.Value);
                    Response.Redirect("NRFBDetail.aspx?DepartID=" + departid + "&type=2");
                }
                else
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('保存错误');</script>");
            }
            catch
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('保存中出现异常，请重新保存!');</script>");
            }
        }
    }
}
